package org.openglcharts.listeners;

import java.io.Serializable;
import java.util.Vector;

import org.openglcharts.common.Value;
import org.openglcharts.common.ValueContainer;

public class LineChart2DChannel extends ValueContainer implements Serializable {

	private static final long serialVersionUID = -5403566259722780702L;

	private Vector<LineChart2DChannelListener> listeners = new Vector<LineChart2DChannelListener>();
	private float[] colorHighlight = { 1.0f, 1.0f, 1.0f };
	private float[] color = { 0.5f, 0.5f, 0.5f };
	private boolean highlighted = false;
	private String name = "noname";

	public LineChart2DChannel(String name) {
		this.name = name;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public float[] getColor() {
		if (!this.highlighted) {
			return this.color;
		} else {
			return this.colorHighlight;
		}
	}

	public void setColor(float red, float green, float blue) {
		this.color = new float[] { red, green, blue };
	}

	public void highlight(boolean highlight) {
		this.highlighted = highlight;
	}

	@Override
	public void add(Value value) {
		super.add(value);
		for(LineChart2DChannelListener listener : this.listeners)
		{
			listener.valueAdded(value);
		}
	};

	public void addValueListener(LineChart2DChannelListener listener) {
		this.listeners.add(listener);
	}

	public void removeValueListener(LineChart2DChannelListener listener) {
		this.listeners.remove(listener);
	}
}